package com.surfilter.risk.entity;

import com.google.common.collect.Lists;

import java.util.List;

/**
 * Page
 * Dis:分页实体
 * Created by jstarseven on 2017/5/11.
 */
public class Page<T> {
    //每页显示记录数   pageSize
    private Integer pageSize;
    //当前页数	pageNumber
    private Integer pageNumber;
    //总页数	totalPage
    private Integer totalPage;
    //总记录数	totalRow
    private Integer totalRow;

    //分页开始
    private Integer begin;
    //分页结束
    private Integer end;


    private List<T> list = Lists.newArrayList();

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(Integer pageNumber) {
        this.pageNumber = pageNumber;
    }

    public Integer getTotalPage() {
        // 根据总行数，计算总页数
        if (totalRow % pageSize == 0) {
            totalPage = totalRow / pageSize;
        } else {
            totalPage = totalRow / pageSize + 1;
        }
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getTotalRow() {
        return totalRow;
    }

    public void setTotalRow(Integer totalRow) {
        this.totalRow = totalRow;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public Integer getBegin() {
        begin = (pageNumber - 1) * pageSize;
        return begin;
    }

    public void setBegin(Integer begin) {
        this.begin = begin;
    }

    public Integer getEnd() {
        end = pageNumber * pageSize + 1;
        return end;
    }

    public void setEnd(Integer end) {
        this.end = end;
    }

    @Override
    public String toString() {
        return "Page{" +
                "pageSize=" + pageSize +
                ", pageNumber=" + pageNumber +
                ", totalPage=" + totalPage +
                ", totalRow=" + totalRow +
                ", begin=" + begin +
                ", end=" + end +
                ", list=" + list +
                '}';
    }
}
